var publicApi = require('../../../../script/public.js');
Component({
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    orderinfo: {
      type: Object,
      value: null
    },
  },
  observers: {
    'orderinfo': function (val) {
      if (val != null) {
        this.setDefaultValue();
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    ProcHandReasonList: [],
    SolveWayList: [],
    SubmitData: {
      SOLVEWAY: '',
      SOLVEREMARK: '',
      ProcHandReason: '',
      OTHERREASON: ''
    }
  },
  lifetimes: {
    attached() {
      this.getList('ProcHandReason');
      this.getList('SolveWay');
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getList(type) {     
      publicApi.GetPCodeList({
        CODE_TYPE: type,
      }).then(res => {
        if (res.code === 200) {
          const resData = res.data || [];
          const list = resData.find(item => item.VALUE === '007');
          if (list) {
            const children = [...list.Childrens];
            children.push({NAME: '其他',VALUE: '099'});
            if (type === 'ProcHandReason') {
              this.setData({
                ProcHandReasonList: children,
                // "SubmitData.ProcHandReason": children[0].VALUE
              });
            } else if (type === 'SolveWay') {
              this.setData({
                SolveWayList: children,
                // "SubmitData.SOLVEWAY": children[0].VALUE
              });
            }
          }
        }
      });
    },
    ProcHandReasonRadioChange(e) {
      this.setData({
        "SubmitData.ProcHandReason": e.detail.value
      });
    },
    OtherReasonChange: function (e) {
      this.setData({
        "SubmitData.OTHERREASON": e.detail.value
      });
    },
    SolveWayRadioChange(e) {
      this.setData({
        "SubmitData.SOLVEWAY": e.detail.value
      });
    },
    SolveRemarkChange: function (e) {
      this.setData({
        "SubmitData.SOLVEREMARK": e.detail.value
      });
    },
    setDefaultValue() {
      this.setData({
        // "SubmitData.SOLVEWAY": this.data.orderinfo.SolveWay,
        // "SubmitData.SOLVEREMARK": this.data.orderinfo.SolveRemark,
        "SubmitData.ProcHandReason": this.data.orderinfo.ProcHandReason,
        "SubmitData.OTHERREASON": this.data.orderinfo.OtherReason,
      });
    },
    getSubmitData(isCheck = true) {
      if(isCheck){
        // if (this.data.SubmitData.SOLVEWAY == null || this.data.SubmitData.SOLVEWAY == '') {
        //   wx.showToast({
        //     title: '解决措施不能为空！',
        //     icon: 'none',
        //     duration: 2000
        //   });
        //   return null;
        // }else{
        //   if(this.data.SubmitData.SOLVEWAY === '099'){
        //     if(this.data.SubmitData.SOLVEREMARK == null || this.data.SubmitData.SOLVEREMARK == ''){
        //       wx.showToast({
        //         title: '其他措施文字说明不能为空！',
        //         icon: 'none',
        //         duration: 2000
        //       });
        //       return null;
        //     }
        //   }
        // }
        if (this.data.SubmitData.ProcHandReason == null || this.data.SubmitData.ProcHandReason == '') {
          wx.showToast({
            title: '具体情况不能为空！',
            icon: 'none',
            duration: 2000
          });
          return null;
        }else{
          if(this.data.SubmitData.ProcHandReason === '099'){
            if(this.data.SubmitData.OTHERREASON == null || this.data.SubmitData.OTHERREASON == ''){
              wx.showToast({
                title: '其他情况文字说明不能为空！',
                icon: 'none',
                duration: 2000
              });
              return null;
            }
          }
        }
      }
      const submitData = {
        ProcHandReason: this.data.SubmitData.ProcHandReason,
        OTHERREASON: this.data.SubmitData.OTHERREASON,
        // SOLVEWAY: this.data.SubmitData.SOLVEWAY,
        // SOLVEREMARK: this.data.SubmitData.SOLVEREMARK,
      }
      return submitData;
    },
  }
})